var express = require('express');  
var https = require('https')
// var bodyParser = require('body-parser');  
var app = express();  
const hostname = '172.18.214.227';
// const hostname = '127.0.0.1';


  
app.get('/getAccessToken', function(request, response){  
  // 输出 JSON 格式  
  var data = "";
  https.get('https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wxcdf62175ea3c1f1e&secret=030065f910c95c7ab00a7a655b16606d',function(res){
    var buffer = [],result = "";
                //监听 data 事件
    res.on('data',function(data){
        buffer.push(data);
    });
    //监听 数据传输完成事件
    res.on('end',function(){
        result = Buffer.concat(buffer).toString('utf-8');
        //将最后结果返回
        data = result
    });
  });
   // data = {  
   //    "access_token": "TcfrUrP8LdNXC07Tdr8yMvJfI660yHopXGAdQ9G8oFST_MnGKbJIisHM__0Jt9t-eFThvXv5ZvATkYOZB8OO4-0ARlrkwBIqlEl_s9JRyRFpNaAF-ZIBJBvSODMJhyo6ZYQjACALKC", 
   //    "expires_in": 7200
   // };  
   console.log(data);  
   //  response.end(JSON.stringify(data));  
   response.json(data);  
});  
  
// // 创建 application/x-www-form-urlencoded 编码解析  
// var urlencodedParser = bodyParser.urlencoded({ extended: false })  
// curl -d 'grant_type=client_credential&appid=wxcdf62175ea3c1f1e&secret=030065f910c95c7ab00a7a655b16606d' https://api.weixin.qq.com/cgi-bin/token

  
// app.post('/post', urlencodedParser, function(request, response){  
//   // 输出 JSON 格式  
//    data = {  
//        'name':request.body.name,  
//        'gender':request.body.gender  
//    };  
//    console.log(data);  
//   //  response.end(JSON.stringify(data));  
//    response.json(data);  
// });  
  
// app.get('/roby', function(request, response){  
//   var hostName = request.hostname;  
//   console.log("hostName: %s", hostName);  
//   response.send("I got you!");  
// });  
  
var server = app.listen(3000, hostname, function(){  
  var host = server.address().address;  
  var port = server.address().port;  
  console.log("address: %s, port: %d", host, port);  
});  